import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { resolve } from "path";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue()],
  server: {
    open: true,
    port: 4000,
    //配置代理，实现跨域
    proxy: {
      "/api": {
        // target: "http://101.200.146.23:8088",
        target: "http://localhost:8088",
        changeOrigin: true,
        rewrite: (url) => url.replace(/^\/api/, "/api"),
      },
    },
  },
  //配置别名
  resolve: {
    alias: [
      {
        find: "@",
        replacement: resolve(__dirname, "src"),
      },
    ],
  },
  css: {
    devSourcemap: false,
  },
  // 优化构建选项
  build: {
    minify: "terser",
    chunkSizeWarningLimit: 1500,
    rollupOptions: {
      output: {
        manualChunks: {
          "markdown-chunk": ["markdown-it"],
          "highlight-chunk": ["highlight.js"],
          vendor: ["vue", "vue-router", "element-plus"],
        },
      },
    },
  },
  // 优化预编译选项，提高加载速度
  optimizeDeps: {
    include: [
      "vue",
      "vue-router",
      "element-plus",
      "markdown-it",
      "highlight.js",
    ],
  },
});
